<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form :inline="true" :model="formModel">
        <el-form-item class="no-warn-item" label="分类代码:" prop="clcd">
          <el-select v-model="formModel.clcd" clearable filterable>
            <el-option v-for="item in clcdOptions" :key="item.clcd" :label="item.describe" :value="item.clcd"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="no-warn-item" label="代码类型:" prop="clcdType">
          <hey-select v-model="formModel.clcdType" clcd="clcd_type_cd" />
        </el-form-item>
        <el-row class="submit-area">
          <el-col :span="24">
            <el-button type="primary" v-if="hasPermission('data_select')" plain @click="queryList(false)">查询</el-button>
            <el-button type="primary" v-if="hasPermission('data_add')" plain @click="handleAdd">新增</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <hey-table ref="table" :columns="columns" :is-select="false">
      <template slot="tools">
        <el-table-column
          label="操作"
          width="160"
          fixed="right"
          header-align="center"
          align="center"
        >
          <template slot-scope="{row}">
            <span class="hey_tools_btn" v-if="hasPermission('data_edit')" @click="handleEdit(row)">编辑</span>
            <span class="hey_tools_btn" v-if="hasPermission('data_del')&& row.clcdType!='01'" @click="handleDelete(row)">删除</span>
          </template>
        </el-table-column>
      </template>
    </hey-table>
    <el-dialog
      v-dialogDrag
      v-if="dialogVisible"
      :close-on-click-modal="false"
      title="数据字典信息"
      :visible.sync="dialogVisible"
      width="80%"
    >
      <data-mnt :page-type="operType" :edit-data="editData" @mntSuc="queryList" />
    </el-dialog>

  </div>
</template>

<script>
export default {
  name: 'DataList',
  components: {
    DataMnt: () => import('./data-mnt')
  },
  props: {},
  data() {
    return {
      dialogVisible: false,
      clcdOptions:[],
      operType: '',
      editData: {},
      formModel: {
        clcd: '',
        isDelete: '0',
        clcdType: '',
      },
      columns: [
        { title: '分类代码', key: 'clcd' },
        { title: '分类描述', key: 'describe' },
        { title: '代码类型', key: 'clcdType',clcd:'clcd_type_cd' },
        { title: '数据代码', key: 'dataKey'},
        { title: '数据码值', key: 'dataValue' },
        { title: '显示顺序', key: 'sortNum' },
        { title: '是否子级', key: 'isChild',clcd:'ind_cd' },
        { title: '父级分类代码', key: 'parentClcd' },
        { title: '父级分类描述', key: 'parentDescribe' },
        { title: '父级数据代码', key: 'parentDataKey' },
        { title: '父级数据码值', key: 'parentDataValue' },
        { title: '创建时间', key: 'createTime' },
        { title: '创建人', key: 'createUsername' },
        { title: '最后修改时间', key: 'lastUpdateTime'},
        { title: '最后修改人', key: 'lastUpdateUsername' },
      ]
    }
  },
  computed: {},
  mounted() {
    this.getClcd()
    // this.queryList(false)
  },
  methods: {
    //获取分类代码
    getClcd(){
      this.post('/dictionary/getAllClcd', {}).then(res => {
        this.clcdOptions = res
      })
    },
    queryList() {
      this.$refs.table.query('/dictionary/queryDataDictionary', this.formModel, '', false)
    },
    handleAdd() {
      this.operType = 'add'
      this.dialogVisible = true
    },
    handleEdit(row) {
      this.dialogVisible = true
      this.operType = 'edit'
      this.editData = row || {}
    },
    handleDelete(row) {
      this.$sure('确认删除？', _ => {
        this.post('/dictionary/maintainDataDictionary', { rcrdId: row.rcrdId,operateType:'03'}).then(_ => {
          this.$info('删除成功', this.queryList)
        })
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
